home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / PRGrUtil.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  4.1 KB  |  152 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PRGrUtil.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef PRGRUTIL_H
  13. #include "PRGrUtil.h"
  14. #endif
  15.  
  16. #ifndef FWRECT_H
  17. #include "FWRect.h"
  18. #endif
  19.  
  20. #ifndef FWPOINT_H
  21. #include "FWPoint.h"
  22. #endif
  23.  
  24. #ifndef FWFXMATH_H
  25. #include "FWFxMath.h"
  26. #endif
  27.  
  28. #ifdef FW_BUILD_MAC
  29. #pragma segment FWGraphx_PrivateGrUtil
  30. #endif
  31.  
  32. #ifdef FW_BUILD_MAC
  33. //----------------------------------------------------------------------------------------
  34. //    FW_PrivMacGetPortTextStyle
  35. //----------------------------------------------------------------------------------------
  36.  
  37. void SL_API    FW_PrivMacGetPortTextStyle(TextStyle& theTextStyle)
  38. {
  39.     GrafPtr curPort = FW_QDGlobals.thePort;
  40.     theTextStyle.tsFont = curPort->txFont;
  41.     theTextStyle.tsFace = curPort->txFace;
  42.     theTextStyle.tsSize = curPort->txSize;
  43. }
  44. #endif
  45.  
  46. #ifdef FW_BUILD_MAC
  47. //----------------------------------------------------------------------------------------
  48. //    FW_PrivMacSetPortTextStyle
  49. //----------------------------------------------------------------------------------------
  50.  
  51. void SL_API    FW_PrivMacSetPortTextStyle(const TextStyle& theTextStyle)
  52. {
  53.     ::TextFont(theTextStyle.tsFont);
  54.     ::TextFace(theTextStyle.tsFace);
  55.     ::TextSize(theTextStyle.tsSize);
  56. #endif
  57.  
  58. #ifdef FW_BUILD_WIN
  59.  
  60. //----------------------------------------------------------------------------------------
  61. // FW_WinPrivGetDisplayColorInfo
  62. //----------------------------------------------------------------------------------------
  63.  
  64. void SL_API    FW_PrivWinGetDisplayColorInfo(short& planeCount, short& bitsPixel)
  65. {
  66.     static short gPlaneCount = -1;
  67.     static short gBitsPixel = -1;
  68.     
  69.     if(gPlaneCount == -1)
  70.     {
  71.         HDC hDC = ::GetDC(NULL);
  72.         gPlaneCount = (short) ::GetDeviceCaps(hDC, PLANES);
  73.         gBitsPixel = (short) ::GetDeviceCaps(hDC, BITSPIXEL);
  74.         ::ReleaseDC(NULL, hDC);
  75.     }
  76.     
  77.     planeCount = gPlaneCount;
  78.     bitsPixel = gBitsPixel;
  79. }
  80.  
  81. #endif
  82.  
  83. //----------------------------------------------------------------------------------------
  84. //    FW_PrivCalcArcPoints
  85. //----------------------------------------------------------------------------------------
  86. //    [KVV] Need to be changed. Could do better than that.
  87.  
  88. void SL_API    FW_PrivCalcArcPoints(const FW_CPlatformRect& rect, 
  89.                              short angle,
  90.                              FW_CPlatformPoint& arcPoint)
  91. {
  92.     if (angle >= 360)
  93.         angle = angle % 360;
  94.     else if(angle < 0)
  95.         angle = (angle % 360) + 360;
  96.         
  97.     FW_PlatformCoordinate middleX    = (rect.right + rect.left) / 2;
  98.     FW_PlatformCoordinate middleY    = (rect.right + rect.left) / 2;
  99.     const FW_Fixed halfX           = FW_IntToFixed((rect.right - rect.left) / 2);
  100.     const FW_Fixed halfY           = FW_IntToFixed((rect.bottom - rect.top) / 2);
  101.     
  102.     switch (angle)
  103.     {
  104.         case 0:
  105.             arcPoint.Set(middleX, rect.top);
  106.             break;
  107.         case 45:
  108.             arcPoint.Set(rect.right, rect.top);
  109.             break;
  110.         case 90:
  111.             arcPoint.Set(rect.right, middleY);
  112.             break;
  113.         case 135:
  114.             arcPoint.Set(rect.right, rect.bottom);
  115.             break;
  116.         case 180:
  117.             arcPoint.Set(middleX, rect.bottom);
  118.             break;
  119.         case 225:
  120.             arcPoint.Set(rect.left, rect.bottom);
  121.             break;
  122.         case 270:
  123.             arcPoint.Set(rect.left, middleY);
  124.             break;
  125.         case 315:
  126.             arcPoint.Set(rect.left, rect.top);
  127.             break;
  128.  
  129.         default:
  130.             FW_Fixed fxRad = (FW_IntToFixed(90 - angle) * FW_kFixedPI) / FW_IntToFixed(180);
  131.             if (angle < 45)
  132.                 arcPoint.Set(FW_FixedToInt(halfX * FW_Cos(fxRad)) + middleX, rect.top);
  133.             else if (angle > 45 && angle < 135)
  134.                 arcPoint.Set(rect.right, FW_FixedToInt(halfY * FW_Sin(fxRad)) + middleY);
  135.             else if (angle < 180)
  136.                 arcPoint.Set(FW_FixedToInt(halfX * FW_Cos(fxRad)) + middleX, rect.bottom);
  137.             else
  138.             {
  139.                 fxRad = (FW_IntToFixed(angle - 270) * FW_kFixedPI) / FW_IntToFixed(180);
  140.                 if (angle < 45)
  141.                     arcPoint.Set(middleX - FW_FixedToInt(halfX * FW_Cos(fxRad)), rect.top);
  142.                 else if (angle > 45 && angle < 135)
  143.                     arcPoint.Set(rect.right, middleY - FW_FixedToInt(halfY * FW_Sin(fxRad)));
  144.                 else if (angle < 180)
  145.                     arcPoint.Set(middleX - FW_FixedToInt(halfX * FW_Cos(fxRad)), rect.bottom);
  146.             }
  147.             break;
  148.     }
  149. }
  150.  
  151.